#!/usr/bin/env bash

# 当使用未初始化的变量时，程序自动退出
set -u

# 当任何一行命令执行失败时，自动退出脚本
set -e

# 在运行结果之前，先输出执行的那一行命令
set -x

readonly PG_DUMP_PATH=/usr/local/bin
readonly DATABASE_LOCAL_STORE_PATH=/Users/dolphin/CloudStation/dolphin-proj/data

CURRENT_TIME=`date '+%Y%m%d%H%M%S'`

${PG_DUMP_PATH}/pg_dump -v -h prod-book-db -U postgres dolphin > ${DATABASE_LOCAL_STORE_PATH}/dolphin-fulldb-backup-${CURRENT_TIME}.bak

# input password automatic
expect "Password:"
send "postgres\r"
